import React, {Component} from 'react';
import {
    Scene,
    Router,
    Lightbox, Drawer, Tabs, Stack, Modal, Actions
} from 'react-native-router-flux';
import Login from "../page/login";
import Main from "../page/main";
import SearchNavBar from "../component/widget/SearchNavBar";
import TabIcon, {TabIconPath} from "../component/common/TabIcon";
import * as Constant from "../style/constant";
import Mine from "../page/mine";
import ProductList from "../page/productList";
import Cert from "../page/cert";
import styles, {navBarHeight} from "../style";
import {Platform, StatusBar, Text, View} from "react-native";
import CheckBill from "../page/primary/checkBill";
import ProductDetail from "../page/primary/productDetail";
import searchPage from "../page/primary/searchPage";
import AddressSetting from "../page/primary/addressSetting";
import PayWay from "../page/primary/payWay";
import ProfileSetting from "../page/mine/profileSetting";
import AddressManage from "../page/mine/addressManage";
import Orders from "../page/mine/orders";
import Evaluation from "../page/primary/evaluation";
import Income from "../page/mine/income";
import IncomeDetail from "../page/mine/incomeDetail";
import WithDraw from "../page/mine/withDraw";
import AddBankCard from "../page/mine/addBankCard";
import SelectBankCard from "../page/mine/selectBankCard";
import Verified from "../page/primary/verified";
import VerifiedResult from "../page/primary/verifiedResult";
import Team from "../page/mine/team";
import BackBtn from "../component/page/primary/payWay/backBtn";
import Welcome from "../page/welcome";
import CustomBackButton from "../component/widget/CustomBackButton";
import {hidePicker} from "../component/common/PickerProxy";
import CommonIconBtn from "../component/common/CommonIconBtn";
import ShareCode from "../page/login/shareCode";
import CardStackStyleInterpolator from 'react-navigation/src/views/CardStack/CardStackStyleInterpolator';
import SharePage from "../page/mine/sharePage";
import CustomRightButton from "../component/widget/CustomRightButton";
import ConcatUs from "../page/mine/concatUs";
import WithDrawDetail from "../page/mine/withDrawDetail";
import SignInDetail from "../page/mine/signInDetail";

// enum StatusBarStyle {
//     lightContent = "light-content",
//     darkContent = "dark-content",
// }
//
// function changeStatusBar(color: string, content: StatusBarStyle) {
//
//     if (Platform.OS === "ios") {
//         StatusBar.setBarStyle(content, true);
//         // StatusBar.setTranslucent(true)
//     }
// }

const getRouter = () => {
    const titleStyle: any = {color: "#000", alignItems: "center", fontSize: 18, fontWeight: "normal"};
    return (
        <Router>
            <Lightbox>
                <Scene
                    transitionConfig={() => ({
                        screenInterpolator: (props) => {
                            switch (props.scene.route.params.direction) {
                                case 'vertical':
                                    return CardStackStyleInterpolator.forVertical(props);
                                case 'fade':
                                    return CardStackStyleInterpolator.forFade(props);
                                case 'none':
                                    return CardStackStyleInterpolator.forInitial
                                case 'horizontal':
                                default:
                                    return CardStackStyleInterpolator.forHorizontal(props)
                            }
                        }
                    })}
                    direction={"horizontal"}
                    key={"RootStack"}
                    titleStyle={titleStyle}
                    backTitle={null}
                    renderLeftButton={(props) => <CustomBackButton {...props}/>}
                    headerMode={"screen"}
                    navigationBarStyle={styles.navigationBar}>
                    <Scene key={"welcome"} component={Welcome} hideNavBar/>
                    <Scene key="Login" title={"登录"}
                           hideNavBar
                           component={Login}/>
                    <Scene tabs key={"RootTabs"} lazy={false} tabBarPosition={"bottom"}
                           showLabel={false}
                           animationEnabled={false}
                           swipeEnabled={false}
                           tabBarStyle={{
                               height: Constant.tabBarHeight,
                               alignItems: 'center',
                               justifyContent: 'center',
                               backgroundColor: Constant.tabBackgroundColor
                           }}>
                        <Scene key={"Index"} navBar={SearchNavBar}
                               icon={TabIcon}
                               tabTitle={"首页"}
                               tabIconName={TabIconPath.Main}
                               component={Main}/>
                        <Scene key={"Product"} navBar={SearchNavBar}
                               icon={TabIcon}
                               tabTitle={"全部"}
                               tabIconName={TabIconPath.Product}
                               component={ProductList}/>
                        <Scene key={"Cert"}
                               icon={TabIcon}
                               tabTitle={"购物车"}
                               title={"购物车"}
                               tabIconName={TabIconPath.Cert}
                               component={Cert}/>
                        <Scene key={"Mine"}
                               icon={TabIcon}
                               tabTitle={"我的"}
                               navTransparent
                               renderRightButton={SettingBtn}
                               onEnter={Mine.onEnter}
                               tabIconName={TabIconPath.Mine}
                               component={Mine}/>
                    </Scene>
                    <Scene key={"Cert_NavCard"}
                           icon={TabIcon}
                           tabTitle={"购物车"}
                           title={"购物车"}
                           tabIconName={TabIconPath.Cert}
                           component={Cert}/>
                    <Scene key="Team" title={"我的团队"} component={Team}/>
                    <Scene key="ShareCode" title={"邀请码"} component={ShareCode} hideNavBar/>
                    <Scene key="VerifiedResult" title={"实名认证"} component={VerifiedResult}/>
                    <Scene key="Verified" title={"实名认证"} component={Verified}/>
                    <Scene key="SelectBankCard" title={"选择银行卡"} component={SelectBankCard}/>
                    <Scene key="AddBankCard" title={"添加银行卡"} component={AddBankCard}/>
                    <Scene key="WithDraw" title={"积分提现"} component={WithDraw}/>
                    <Scene key="ProfileSetting" onExit={hidePicker} title={"个人设置"} rightTitle={"保存"}
                           rightButtonTextStyle={{marginTop: -5, color: "#555555"}} component={ProfileSetting}/>
                    <Scene key="Income" title={"我的收益"} navTransparent
                           titleStyle={{color: "#fff"}}
                           navBarButtonColor={"#fff"}
                           component={Income}/>
                    <Scene key="IncomeDetail" title={"收益明细"}
                           navigationBarStyle={{backgroundColor: "#629B36"}}
                           navBarButtonColor={"#fff"}
                           titleStyle={{color: "#fff"}} component={IncomeDetail}/>
                    <Scene key="SignInDetail" title={"签到明细"}
                           navigationBarStyle={{backgroundColor: "#629B36"}}
                           navBarButtonColor={"#fff"}
                           titleStyle={{color: "#fff"}} component={SignInDetail}/>
                    <Scene key="Evaluation" title={"订单评价"} component={Evaluation}/>
                    <Scene key="Orders" title={"我的订单"} component={Orders}/>
                    <Scene key="WithDrawDetail" title={"提现明细"}
                           navigationBarStyle={{backgroundColor: "#629B36"}}
                           navBarButtonColor={"#fff"}
                           titleStyle={{color: "#fff"}}
                           component={WithDrawDetail}/>

                    <Scene key="ConcatUs" title={"联系我们"} navigationBarStyle={{backgroundColor: "#629B36"}}
                           titleStyle={{color: "#fff"}} navBarButtonColor={"#fff"} component={ConcatUs}/>
                    <Scene key="SharePage" renderRightButton={() => <CustomRightButton onRight={SharePage.onRight}/>}
                           title={"分享"} component={SharePage}/>
                    <Scene key="PayWay" panHandlers={null} renderLeftButton={() => <BackBtn/>} title={"选择支付方式"}
                           component={PayWay}/>
                    <Scene key="AddressSetting" title={"新增收货地址"} component={AddressSetting}/>
                    <Scene key="CheckBill" title={"买单"} component={CheckBill}/>
                    <Scene component={ProductDetail} key={"ProductDetail"} title={"商品详情"}/>
                    <Scene component={searchPage} hideNavBar={true} headerMode={"float"} key={"searchPage"}
                           title={"搜索页"}/>
                    <Scene key="AddressManage" title={"管理收货地址"} component={AddressManage}/>
                </Scene>
            </Lightbox>
        </Router>
    )
};

function SettingBtn() {
    return <CommonIconBtn onPress={() => Actions.ProfileSetting()}
                          icon={{
                              name: "settings",
                              size: 22,
                              color: "#fff"
                          }}
                          style={{
                              marginRight: 22
                          }}
                          activeOpacity={.85}
    />
}

export default getRouter;